package com.ryder.subject.infra.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ryder.subject.infra.basic.entity.SubjectCollect;
import com.ryder.subject.infra.basic.mapper.SubjectCollectMapper;
import com.ryder.subject.infra.basic.service.SubjectCollectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 题目收藏表 表服务实现类
 *
 * @author ryder
 * @version 1.0
 * @since 1.0 // 版本号，指明从哪个版本开始
 * 更新日期: 2025-03-16 11:29:20
 */
@Service("SubjectCollectService")
public class SubjectCollectServiceImpl implements SubjectCollectService {

    @Resource
    private SubjectCollectMapper subjectCollectMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectCollect queryById(Long id) {
        return this.subjectCollectMapper.selectById(id);
    }

    /**
     * 新增数据
     *
     * @param subjectCollect 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(SubjectCollect subjectCollect) {
        return this.subjectCollectMapper.insert(subjectCollect);
    }

    /**
     * 修改数据
     *
     * @param subjectCollect 实例对象
     * @return 实例对象
     */
    @Override
    public int update(SubjectCollect subjectCollect) {
        return this.subjectCollectMapper.updateById(subjectCollect);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.subjectCollectMapper.deleteById(id) > 0;
    }

    /**
     * 条件查询
     *
     * @param subjectCollect 条件
     * @return 实例对象
     */
    @Override
    public SubjectCollect queryByCondition(SubjectCollect subjectCollect) {

        LambdaQueryWrapper<SubjectCollect> queryWrapper = Wrappers.<SubjectCollect>lambdaQuery()
                .eq(Objects.nonNull(subjectCollect.getId()), SubjectCollect::getId, subjectCollect.getId())
                .eq(Objects.nonNull(subjectCollect.getSubjectId()), SubjectCollect::getSubjectId, subjectCollect.getSubjectId())
                .eq(Objects.nonNull(subjectCollect.getLikeUserId()), SubjectCollect::getLikeUserId, subjectCollect.getLikeUserId())
                .eq(Objects.nonNull(subjectCollect.getStatus()), SubjectCollect::getStatus, subjectCollect.getStatus())
                .eq(Objects.nonNull(subjectCollect.getCreatedBy()), SubjectCollect::getCreatedBy, subjectCollect.getCreatedBy())
                .eq(Objects.nonNull(subjectCollect.getCreatedTime()), SubjectCollect::getCreatedTime, subjectCollect.getCreatedTime())
                .eq(Objects.nonNull(subjectCollect.getUpdateBy()), SubjectCollect::getUpdateBy, subjectCollect.getUpdateBy())
                .eq(Objects.nonNull(subjectCollect.getUpdateTime()), SubjectCollect::getUpdateTime, subjectCollect.getUpdateTime())
                .eq(Objects.nonNull(subjectCollect.getIsDeleted()), SubjectCollect::getIsDeleted, subjectCollect.getIsDeleted())
                ;
        return subjectCollectMapper.selectOne(queryWrapper);

    }

    @Override
    public int countByCondition(SubjectCollect subjectCollect) {
        return this.subjectCollectMapper.countByCondition(subjectCollect);
    }

    @Override
    public List<SubjectCollect> queryPage(SubjectCollect subjectCollect, int start, Integer pageSize) {
        return this.subjectCollectMapper.queryPage(subjectCollect, start, pageSize);
    }

    @Override
    public void batchInsert(List<SubjectCollect> subjcetCollectList) {
        this.subjectCollectMapper.batchInsert(subjcetCollectList);
    }

}
